cmake_minimum_required(VERSION 3.10)

#project(north_dlt698)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Os -fPIC")

set(OTHER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/hex.cpp
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/spec.cpp
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/findfirst.cpp
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/common.cpp 
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/CThreadNotify.cpp 
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/CConfigManager.cpp 
              ${CMAKE_CURRENT_SOURCE_DIR}/../../common/src/CMosquittoManager.cpp
              ${CMAKE_CURRENT_SOURCE_DIR}/../../datacenter/src/MappingRelationManager.cpp)

aux_source_directory(./src SRC)

#include_directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../dlt698/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../common/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../logger/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../datacenter/include)

#library_directories
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/logger)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/north/dlt698)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/settings)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/db)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/serialProxy)
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/datacenter)

# add_executable(NetManager ${SRC} ${OTHER_SRC})

add_library(NetManager SHARED ${SRC}) # 生成动态库或共享库

SET_TARGET_PROPERTIES(NetManager PROPERTIES VERSION 1.0.0 SOVERSION 1)

install(TARGETS NetManager LIBRARY DESTINATION ${CMAKE_LIBRARY_PATH})

TARGET_LINK_LIBRARIES(NetManager libnorth_dlt698.so libsysinfo.so liblogger.so pthread libssl.so libcrypto.so libmosquitto.so 
                        libsysconfig.so libsettings.so libyaml-cpp.so libcjson.so liblib60870.so
                        libsqlite3.so libdb.so libserialproxy.so libdl.so libdatacenter.so)
# add_library(NetManager SHARED ${SRC}) # 生成动态库或共享库
# SET_TARGET_PROPERTIES(NetManager PROPERTIES VERSION 1.0.0 SOVERSION 1)

# install(TARGETS NetManager LIBRARY DESTINATION ${CMAKE_LIBRARY_PATH})

add_custom_command(TARGET  NetManager
        POST_BUILD
        COMMAND echo "NetManager builded finished."
        COMMAND ${CMAKE_STRIP} "$<TARGET_FILE:NetManager>"
        COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:NetManager> ${CMAKE_BINARY_PATH}/NetManager
        #COMMAND ${CMAKE_COMMAND} -E copy  "${CMAKE_CURRENT_SOURCE_DIR}/include/global.h" ${CMAKE_INCLUDE_PATH}/global.h
#        COMMAND ${CMAKE_COMMAND} -E copy  $<TARGET_FILE:north_dlt698> ${CMAKE_LIBRARY_PATH}/libnorth_dlt698.so 
       COMMENT  "NetManager is install finished"
       )